<!DOCTYPE html>
<html lang="en"  style="background-color: #fff">
<head>
    <meta charset="UTF-8">
    <title>选择系统角色</title>
</head>
<body>
    <div class="layui-form" style="border:1px solid #c0e4f9;padding:30px;width:25%;position: absolute;left:37.5%;top:30%;background: #ff">
            <div>
                <span style="width:100px;font-weight: bold">请选择系统:</span>
                <div style="margin-top: 20px">
                    <select id="currentSys"  lay-filter="currentSys">
                        <option value="" selected>---请选择---</option>
                        <#list subSystemList as item>
                             <option value="${item.systemId}">${item.sysName}</option>
                        </#list>
                    </select>
                </div>
            </div>
            <div style="margin-top: 30px">
                <span style="width:100px;font-weight: bold">请选择角色:</span>
                <div style="margin-top: 20px">
                    <select value="" id="currentRole" lay-filter="currentRole">
                        <option selected>---请选择---</option>
                    </select>
                </div>
            </div>
    </div>


<link rel="stylesheet" href="./layui/css/layui.css" media="all" />
<script type="text/javascript">
    var __ctx = "${ctx}";
</script>
<script src="./layui/layui.js"></script>
<script src="./public/component.js"></script>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(["index","layer","setter",'form','common'], function(){
        var setter=layui.setter;
        var $=layui.jquery;
        var form=layui.form;
        var common=layui.common;
        form.on('select(currentSys)', function(data){
            var value = data.value;
            if(value){
                $.ajax({
                    url: serverPath.systemPath + setter.sysLinkPath+ "sysRole/querySwitchBySystemId"
                    ,data: {"systemId":value}
                    ,type:"get"
                    ,dataType:'json'
                    ,success: function(data){
                        if (common.filterRecord(data)) {
                            var list = data.data;
                            if(list){
                                var appendHtml = "";
                                for(var i=0;i<list.length;i++){
                                    appendHtml += " <option value='"+list[i].roleId+"'>"+list[i].roleName+"</option>";
                                }
                                $("#currentRole").append(appendHtml);
                                form.render('select')
                            }
                        } else {
                            window.parent.layer.alert(data.msg);
                        }
                    }
                });
            }
        });
        form.on('select(currentRole)', function(data){
            var systemId = $("#currentSys").val();
            var roleId = data.value;
            if(roleId){
                $.ajax({
                    url: serverPath.systemPath + "/saveCurrentSysAndRole"
                    ,data: {"systemId":systemId,"roleId":roleId}
                    ,type:"post"
                    ,dataType:'json'
                    ,success: function(data){
                        if (common.filterRecord(data)) {
                            window.location.href = serverPath.systemPath +"/index"
                        } else {
                            window.parent.layer.alert(data.msg);
                        }
                    }
                });
            }
        });
    });
</script>
</body>
</html>